home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
-
- global proc int hypergraphConnectionEndMenu(string $editor, string $menu,
- string $node, string $plugName, string $direction, string $type,
- string $disconnectPlug)
- //
- // Description:
- // Called to complete a connection when using the popup connection
- // editing capability in the Hypergraph and Hypershade. It is
- // passed the source plug for the connection and direction so the
- // popup menu that is built only shows attributes that are compatible
- // with the source plug
- //
- {
- string $title;
- string $attrCmd;
- string $cmd;
-
- if($direction == "from") {
- $title = "Inputs";
- $attrCmd = "attributeMenu -inputs "+$node+" -attrType "+$type;
- }else{
- $title = "Outputs";
- $attrCmd = "attributeMenu -outputs "+$node+" -attrType "+$type;
- }
- int $numElements = 2;
-
- string $nodeFrom;
- string $nodeTo;
- string $attrs[] = `eval $attrCmd`;
- if($direction == "from") {
- $nodeFrom = $plugName;
- }else{
- $nodeTo = $plugName;
- }
- int $postMenu;
- int $length = size($attrs);
- if($length == $numElements) {
- if($direction == "from") {
- $nodeTo = $node+"."+$attrs[0];
- }else{
- $nodeFrom = $node+"."+$attrs[0];
- }
- string $plug = `connectionInfo -sfd $nodeTo`;
- if($plug != "") {
- disconnectAttr $plug $nodeTo;
- }
- if(!`isConnected $nodeFrom $nodeTo`) {
- connectAttr $nodeFrom $nodeTo;
- }
- $postMenu = 0;
- }else if($length != 0) {
- setParent -m $menu;
- popupMenu -e -deleteAllItems $menu;
- menuItem -l $title;
- menuItem -divider true;
- string $dis;
- if($direction == "from") {
- $nodeTo = $node;
- }else{
- $nodeFrom = $node;
- string $plug = `connectionInfo -sfd $nodeTo`;
- if($plug != "") {
- $dis = "disconnectAttr "+$plug+" "+$nodeTo+";";
- }
- }
- string $newPlug;
- int $i = 0;
- for ($i = 0 ; $i < $length ; $i += $numElements) {
- string $name = $attrs[$i];
- int $italicize = ($attrs[$i+1] == "Connected");
-
- // Attribute is a source and node is the destination
- //
- if($direction == "from") {
- $dis = "";
-
- // If moving an existing connection then disconnect the old one
- // This is the more common left to right connection
- //
- if($disconnectPlug != "") {
- $dis = "disconnectAttr "+$nodeFrom+" "+$disconnectPlug+";";
- }
-
- // If connecting to an already connected input then remove
- // its existing connection to avoid a fan in
- //
- $newPlug = $nodeTo+"."+$attrs[$i];
- string $plug = `connectionInfo -sfd $newPlug`;
- if($plug != "") {
- $dis = $dis + "disconnectAttr "+$plug+" "+$newPlug+";";
- }
-
- // Build the menu item with the command
- //
- menuItem -l $attrs[$i]
- -italicized $italicize -boldFont $italicize
- -c ($dis+"connectAttr "+$nodeFrom+" "+$newPlug);
-
- // Attribute is a destination and node is the source.
- // This is the less common right to left connection
- //
- }else{
- $newPlug = $nodeFrom+"."+$attrs[$i];
- menuItem -l $attrs[$i]
- -italicized $italicize -boldFont $italicize
- -c ($dis+"connectAttr "+$newPlug+" "+$nodeTo);
- }
- }
- $postMenu = 1;
- }
- return $postMenu;
- }
-